﻿using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using WMS.OutboundDetailss.Dto;
using WMS.OutboundDetailss;
using WMS.BatchReceivings;
using WMS.BatchReceivings.Dto;

namespace WMS.Web.Controllers
{
    public class BatchReceivingController : Controller
    {
        private readonly IBatchReceivingService _repository;

        public BatchReceivingController(IBatchReceivingService repository)
        {
            _repository = repository;
        }

        public IActionResult List()
        {
            return View();
        }

        public IActionResult Add()
        {
            return View();
        }

        public IActionResult Update(int id)
        {
            ViewBag.id = id;
            return View();
        }

        public async Task<int> AddBatchReceiving(BatchReceivingDto batchReceivingDto)
        {
            var result = await _repository.AddBatchReceiving(batchReceivingDto);
            return result;
        }

        public async Task<JsonResult> GetBatchReceivingList(string? createName, int page = 1, int limit = 10)
        {
            var result = await _repository.GetBatchReceivingList(createName, page, limit);
            return Json(new { data = result.Queryable, count = result.RowCount, code = 0 });
        }

        public async Task<int> DeleteBatchReceiving(int id)
        {
            var result = await _repository.DeleteBatchReceiving(id);
            return result;
        }

        public async Task<JsonResult> GetBatchReceivingInfo(int id)
        {
            var list = _repository.GetBatchReceivingInfo(id);
            return Json(new { data = list.Result });

        }

        public async Task<int> UpdateBatchReceiving(BatchReceivingDto batchReceivingDto)
        {
            var result = await _repository.UpdateBatchReceiving(batchReceivingDto);
            return result;
        }
    }
}
